Popular Searches
Popular Course Categories
Popular Courses

Date Functions

Tableau Calculated Fields

Date Functions in Tableau – Complete Detailed Notes

Date functions in Tableau are used to analyze, calculate, compare, extract, modify, and format date and time values. They help users analyze sales trends, compare monthly performance, calculate delivery durations, track customer registrations, identify overdue orders, and build time-based dashboards.

Course: JustAcademy Tableau Training

Course Demo: Register for a Tableau Course Demo


1. Learning Objectives

After completing this topic, you will be able to:

  • Understand date and datetime data types in Tableau.
  • Extract the year, month, quarter, day, and other date parts.
  • Calculate the difference between two dates.
  • Add or subtract days, weeks, months, and years.
  • Group dates into months, quarters, and years.
  • Convert text values into date values.
  • Create relative-date calculations and identify overdue records.
  • Calculate order-processing times and customer durations.
  • Create date-based charts, filters, and dashboards.

2. What Are Date Functions?

Date functions are built-in Tableau functions that operate on date and datetime values. A date value represents a calendar date, while a datetime value can include both the date and time.

Examples of Date Values

  • #2026-10-14# – a date value.
  • #2026-10-14 10:30:00# – a datetime value.
  • "2026-10-14" – a string that looks like a date but is still text until converted.

In Tableau, a field recognized as a date or datetime receives a date-related data-type icon in the Data pane. Correct date recognition is important because date functions, date hierarchies, and date filters depend on the field's data type.

Example Dataset

Order ID Order Date Ship Date Delivery Date Sales
ORD001 2026-01-05 2026-01-07 2026-01-10 12000
ORD002 2026-02-12 2026-02-14 2026-02-18 8500
ORD003 2026-03-20 2026-03-21 2026-03-25 15000
ORD004 2026-04-02 2026-04-04 2026-04-08 6000

This dataset can be used to calculate delivery time, group sales by month, and compare performance across periods.


3. Common Date Functions in Tableau

Function Purpose Example
DATE() Converts a recognizable expression into a date. DATE("2026-10-14")
DATEPARSE() Converts text into a date using a specified format. DATEPARSE("dd-MM-yyyy","14-10-2026")
MAKEDATE() Creates a date from year, month, and day numbers. MAKEDATE(2026,10,14)
YEAR() Returns the year. YEAR([Order Date])
MONTH() Returns the month number. MONTH([Order Date])
DAY() Returns the day of the month. DAY([Order Date])
QUARTER() Returns the quarter number. QUARTER([Order Date])
WEEK() Returns the week number. WEEK([Order Date])
DATEPART() Returns a specified date part as an integer. DATEPART('month',[Order Date])
DATENAME() Returns a specified date part as text. DATENAME('month',[Order Date])
DATEADD() Adds or subtracts a date interval. DATEADD('day',7,[Order Date])
DATEDIFF() Calculates the difference between two dates in specified units. DATEDIFF('day',[Order Date],[Ship Date])
DATETRUNC() Truncates a date to a specified level. DATETRUNC('month',[Order Date])
TODAY() Returns the current date. TODAY()
NOW() Returns the current date and time. NOW()
ISDATE() Checks whether a string represents a valid date. ISDATE([Date Text])

Important: Function availability and behavior may vary by Tableau version and data source. Confirm connector support before using a function in a production workbook.


4. DATE() Function

The DATE() function converts a recognizable expression into a date value. It is useful when a field is stored as text or datetime but a date value is required.

Syntax:

DATE(expression)

Example 1: Convert Text to Date

DATE("2026-10-14")

Result: a date representing October 14, 2026, if the input format is recognized.

Example 2: Convert a Field

DATE([Order Date Text])

This converts the Order Date Text field when Tableau recognizes its values as dates.

When to Use DATE()

  • When a source field contains dates stored as strings.
  • When a datetime value needs to be represented as a date.
  • When a calculated field requires a date data type.

If Tableau cannot recognize the input pattern, consider DATEPARSE() where it is supported.


5. DATEPARSE() Function

DATEPARSE() converts a text string into a date using an explicitly specified format. The format must match the arrangement of the input text.

Syntax:

DATEPARSE(date_format, date_string)

Example 1: Day-Month-Year

DATEPARSE("dd-MM-yyyy", "14-10-2026")

Result: October 14, 2026.

Example 2: Year-Month-Day

DATEPARSE("yyyy-MM-dd", "2026-10-14")

Result: October 14, 2026.

Example 3: Text Month

DATEPARSE("dd-MMMM-yyyy", "14-October-2026")

Result: October 14, 2026.

Common Date Format Symbols

Symbol Meaning Example
dd Day of month with two digits 05
d Day of month without a required leading zero 5
MM Month with two digits 10
MMM Abbreviated month name Oct
MMMM Full month name October
yyyy Four-digit year 2026
HH Hour in 24-hour format 16
mm Minutes 30
ss Seconds 45

Use the format symbols supported by the relevant Tableau function and connector. Date parsing can be connector-dependent, so verify the result after conversion.


6. MAKEDATE() Function

MAKEDATE() creates a date from numeric year, month, and day values.

Syntax:

MAKEDATE(year, month, day)

Example

MAKEDATE(2026, 10, 14)

Result: October 14, 2026.

Using Fields

MAKEDATE([Year Number], [Month Number], [Day Number])

This is useful when a dataset stores year, month, and day in separate numeric columns.

Note: Availability depends on the data source. Also validate numeric inputs because some invalid day/month combinations may be adjusted rather than rejected.


7. YEAR(), MONTH(), DAY(), QUARTER(), and WEEK()

These functions extract individual calendar components from a date.

7.1 YEAR()

Returns the year number.

YEAR(#2026-10-14#)

Output: 2026

7.2 MONTH()

Returns the month number from 1 to 12.

MONTH(#2026-10-14#)

Output: 10

7.3 DAY()

Returns the day of the month, usually from 1 to 31.

DAY(#2026-10-14#)

Output: 14

7.4 QUARTER()

Returns the quarter number from 1 to 4.

QUARTER(#2026-10-14#)

Output: 4

7.5 WEEK()

Returns the week number according to the applicable week-start and calendar rules.

WEEK([Order Date])

Use this when analyzing weekly sales, orders, visits, or deliveries. The exact week number may depend on the data source's week-start setting.

Practical Example: Extract Year

YEAR([Order Date])

Drag this calculated field to Columns and Sales to Rows to compare annual sales.


8. DATEPART() Function

DATEPART() returns a selected part of a date as an integer. It is useful for numeric calculations and date-based grouping.

Syntax:

DATEPART(date_part, date, [start_of_week])

Examples

DATEPART('year', [Order Date])

Returns the year number.

DATEPART('month', [Order Date])

Returns a month number from 1 to 12.

DATEPART('quarter', [Order Date])

Returns a quarter number from 1 to 4.

DATEPART('weekday', [Order Date])

Returns a numeric weekday value according to the configured week-start convention.

Common Date Parts

Date Part Meaning Typical result
year Calendar year 2026
quarter Calendar quarter 1–4
month Month number 1–12
day Day of month 1–31
weekday Day of week Numeric weekday
week Week number Typically 1–52
hour Hour component 0–23
minute Minute component 0–59
second Second component 0–60 depending on implementation
iso-week ISO week number Week-based calendar

9. DATENAME() Function

DATENAME() returns a selected part of a date as text rather than an integer. It is useful when labels such as month names or weekday names are required.

Syntax:

DATENAME(date_part, date, [start_of_week])

Example 1: Month Name

DATENAME('month', #2026-10-14#)

Output: October

Example 2: Weekday Name

DATENAME('weekday', #2026-10-14#)

Returns the weekday name for the specified date.

Example 3: Year as Text

DATENAME('year', [Order Date])

Returns the year as a string.

DATEPART() vs DATENAME()

Feature DATEPART() DATENAME()
Return type Integer String
Month example 10 October
Useful for Numeric calculations and sorting Text labels and display
Example DATEPART('month',[Order Date]) DATENAME('month',[Order Date])

10. DATEADD() Function

DATEADD() adds or subtracts a specified interval from a date. A negative interval moves the date backward.

Syntax:

DATEADD(date_part, interval, date)

Example 1: Add Seven Days

DATEADD('day', 7, #2026-10-14#)

Result: October 21, 2026.

Example 2: Add One Month

DATEADD('month', 1, #2026-10-14#)

Result: November 14, 2026.

Example 3: Subtract One Month

DATEADD('month', -1, #2026-10-14#)

Result: September 14, 2026.

Example 4: Calculate a Follow-Up Date

DATEADD('day', 3, [Order Date])

This returns a date three days after the order date and can help calculate a target follow-up date.

Common Intervals

  • 'day' – add or subtract days.
  • 'week' – add or subtract weeks.
  • 'month' – add or subtract months.
  • 'quarter' – add or subtract quarters.
  • 'year' – add or subtract years.
  • 'hour', 'minute', and 'second' – adjust datetime values when supported.

11. DATEDIFF() Function

DATEDIFF() calculates the difference between two dates in a selected unit, such as days, weeks, months, or years. It returns an integer.

Syntax:

DATEDIFF(date_part, start_date, end_date, [start_of_week])

Example 1: Difference in Days

DATEDIFF('day', #2026-10-10#, #2026-10-14#)

Output: 4

Example 2: Calculate Shipping Time

DATEDIFF('day', [Order Date], [Ship Date])

This calculates the number of day boundaries between the order date and shipping date.

Example 3: Calculate Delivery Time

DATEDIFF('day', [Order Date], [Delivery Date])

This calculates the difference between the order and delivery dates.

Example 4: Calculate Customer Tenure in Years

DATEDIFF('year', [Customer Start Date], TODAY())

This counts year boundaries, not necessarily the number of complete years elapsed. For exact tenure, account for whether the anniversary date has occurred.

Important Difference

DATEDIFF() counts boundaries of the specified date part. For example, two dates separated by only a few days can have a month difference of 1 if they fall in different calendar months. It should not be treated as an exact duration in days or hours when using larger date parts.


12. DATETRUNC() Function

DATETRUNC() reduces a date to the beginning of a specified date period. It returns a date value with the lower-level components reset to the start of that period.

Syntax:

DATETRUNC(date_part, date, [start_of_week])

Example 1: Truncate to Month

DATETRUNC('month', #2026-10-14#)

Result: October 1, 2026.

Example 2: Truncate to Quarter

DATETRUNC('quarter', #2026-10-14#)

Result: October 1, 2026, the first day of the fourth quarter.

Example 3: Truncate to Year

DATETRUNC('year', #2026-10-14#)

Result: January 1, 2026.

Example 4: Monthly Sales Grouping

DATETRUNC('month', [Order Date])

Use this calculated field to group dates by month and year consistently, even when the source dates occur on different days of the month.

DATEPART() vs DATETRUNC()

Function Returns Example for October 14, 2026
DATEPART('month', date) Integer 10
DATENAME('month', date) String October
DATETRUNC('month', date) Date October 1, 2026

Note: DATETRUNC() changes the calculated date value. If you only want to change how a date appears in a visualization, adjust the date formatting instead.


13. TODAY() and NOW() Functions

13.1 TODAY()

TODAY() returns the current date according to the applicable local system or data-source context.

TODAY()

Use TODAY() for current-date comparisons, overdue tasks, and date-based filters.

13.2 NOW()

NOW() returns the current date and time.

NOW()

Use NOW() when the current time is also relevant, such as comparing timestamps or tracking elapsed time.

TODAY() vs NOW()

Function Return value Example use
TODAY() Date Identify overdue delivery dates.
NOW() Date and time Compare event timestamps.

With live connections, time-zone behavior can depend on the database and connection environment. Verify the date/time context when building operational dashboards.


14. ISDATE() Function

ISDATE() checks whether a string can be interpreted as a valid date. It returns TRUE or FALSE and is useful when checking text fields before converting them.

Syntax:

ISDATE(string)

Example

ISDATE("2026-10-14")

Output: TRUE, if the input is recognized as a valid date by the relevant implementation.

ISDATE("not-a-date")

Output: FALSE.

Practical use: Use ISDATE() to identify text values that need data cleaning before date calculations. Function support may vary by connector.


15. Building a Date Hierarchy

A date hierarchy lets users drill down from a high-level time period to more detailed levels. Tableau commonly provides date hierarchies for recognized date fields.

Typical Hierarchy

Year
 └── Quarter
      └── Month
           └── Day

How to Use a Date Hierarchy

  1. Connect to a dataset containing a valid date field.
  2. Open a worksheet and locate the date field in the Data pane.
  3. Drag the date field to Rows or Columns.
  4. Select the desired date level, such as Year, Quarter, Month, or Day.
  5. Use the hierarchy drill-down controls to move to a more detailed level when available.
  6. Add a measure such as Sales to analyze performance over time.

Example

Place Order Date on Columns and Sales on Rows. Start with Year, drill down to Quarter, and then Month to inspect changes in sales performance.


16. Discrete and Continuous Dates

Tableau can represent dates as discrete or continuous fields. The choice affects how dates appear in a visualization.

Feature Discrete Date Continuous Date
Appearance Usually blue pill Usually green pill
Visualization behavior Creates separate date headers or categories. Creates an axis across a date range.
Example Separate columns for Jan, Feb, and Mar. A continuous timeline from January to March.
Typical use Comparison by year, quarter, or month. Time-series trends and continuous date axes.

For example, a monthly sales comparison can use discrete months, while a daily sales trend can use a continuous date axis. The best choice depends on the question being analyzed.


17. Creating Relative-Date Calculations

Relative-date calculations compare dates with TODAY() or another reference date. They can identify recent records, upcoming deadlines, and overdue tasks.

Example 1: Orders from the Last 30 Days

[Order Date] >= DATEADD('day', -30, TODAY())
AND [Order Date] <= TODAY()

This Boolean calculation identifies dates between the reference date 30 days ago and today, inclusive. For datetime fields, consider whether to compare dates or timestamps and how to include the full current day.

Example 2: Orders from the Current Year

YEAR([Order Date]) = YEAR(TODAY())

Returns TRUE for records whose order year matches the current year.

Example 3: Orders from the Previous Calendar Month

[Order Date] >= DATETRUNC('month', DATEADD('month', -1, TODAY()))
AND [Order Date] < DATETRUNC('month', TODAY())

This identifies dates in the previous calendar month, excluding the first day of the current month.

Example 4: Upcoming Due Dates

[Due Date] >= TODAY()
AND [Due Date] <= DATEADD('day', 7, TODAY())

This identifies due dates from today through the next seven days, inclusive.


18. Practical Date Calculations

18.1 Calculate Order Processing Time

DATEDIFF('day', [Order Date], [Ship Date])

Shows the number of day boundaries between an order and its shipping date.

18.2 Identify Overdue Orders

IF [Due Date] < TODAY()
AND [Order Status] <> "Completed" THEN
    "Overdue"
ELSE
    "On Time or Completed"
END

This identifies past-due orders that are not marked Completed. Ensure that the status values and NULL handling are appropriate for your dataset.

18.3 Calculate a Delivery Deadline

DATEADD('day', 5, [Order Date])

Creates a target date five days after the order date. This is a calendar-day calculation, not a business-day calculation.

18.4 Label Each Record by Quarter

"Q" + STR(QUARTER([Order Date])) + " " + STR(YEAR([Order Date]))

Example result: Q4 2026. The label can be useful in a chart, although you may need a separate numeric or date field to ensure chronological sorting.

18.5 Calculate Month Start

DATETRUNC('month', [Order Date])

Creates a consistent first-of-month date that can be used to group records for monthly analysis.


19. Date Functions in a Sales Dashboard

Consider a sales dataset containing Order Date, Ship Date, Sales, Profit, Region, and Product Category.

Step 1: Create Year

YEAR([Order Date])

Step 2: Create Month Start

DATETRUNC('month', [Order Date])

Step 3: Calculate Shipping Duration

DATEDIFF('day', [Order Date], [Ship Date])

Step 4: Create a Quarter Label

"Q" + STR(QUARTER([Order Date])) + " " + STR(YEAR([Order Date]))

Step 5: Build the Visualization

  1. Place Month Start on Columns.
  2. Place SUM(Sales) on Rows.
  3. Choose a line chart to show the sales trend.
  4. Add Region and Product Category filters.
  5. Create a second chart showing average shipping duration by month.
  6. Add a date filter so users can choose the reporting period.
  7. Combine the worksheets in a dashboard and add clear titles and tooltips.

Expected Result

  • Monthly sales trends can be compared.
  • Shipping duration can be measured.
  • Users can filter by region, category, and date.
  • Quarterly and yearly performance can be explored through date hierarchies.

20. Common Errors and Troubleshooting

Problem Possible cause Solution
Date function returns an error. Incorrect argument order or syntax. Check the function signature and quotation marks around date parts.
Text date is not recognized. Input format is not automatically recognized. Use DATEPARSE() where supported and match the input format exactly.
Unexpected DATEDIFF result. DATEDIFF counts date-part boundaries rather than exact elapsed units. Choose the appropriate date part and verify the intended business definition.
Incorrect week number. Week-start or ISO calendar settings differ. Check the data source's date properties and the required week convention.
NULL date values. Missing or invalid source dates. Inspect the original data and apply suitable NULL-handling logic.
Unexpected month grouping. Month name is used without year or the date is aggregated differently than expected. Use a year-month date field or DATETRUNC('month', [Date]).
Wrong date display. Display format differs from the desired format. Change date formatting rather than changing the underlying date value unnecessarily.
Current date differs from expectations. Live connection, system time, or time-zone behavior. Verify the time context used by the source and workbook.

21. Best Practices for Date Functions

  • Confirm that source fields have the correct date or datetime data type.
  • Use DATE() for recognizable date expressions and DATEPARSE() when an explicit format is needed and supported.
  • Use DATEPART() for numeric date components and DATENAME() for text labels.
  • Use DATETRUNC() to group records by the beginning of a calendar period.
  • Use DATEDIFF() only after deciding whether the requirement is based on days, months, years, or another date part.
  • Use DATEADD() to calculate deadlines, follow-up dates, and relative periods.
  • Check week-start settings when analyzing weekly trends.
  • Include year with month labels when the analysis covers more than one year.
  • Validate NULL dates and malformed text dates.
  • Check time zones when working with live data and datetime fields.
  • Use date formatting when the goal is only to change how dates are displayed.
  • Test calculations against known dates and boundary cases such as month-end, year-end, and leap days.

22. Practice Exercises

  1. Extract the year from the Order Date field.
  2. Extract the month number from the Order Date field.
  3. Display the full month name using DATENAME().
  4. Calculate the number of days between Order Date and Ship Date.
  5. Add seven days to each order date.
  6. Find the first day of the month for each order.
  7. Create a calculated field that returns TRUE for orders from the current year.
  8. Identify orders with due dates before today.
  9. Convert a text field formatted as 14-10-2026 into a date.
  10. Create a quarter label such as Q4 2026.
  11. Build a line chart of monthly sales.
  12. Build a chart comparing average shipping duration by quarter.

23. Interview Questions and Answers

Q1. What are date functions in Tableau?

Answer: Date functions are built-in functions used to extract date parts, convert text into dates, calculate intervals, add or subtract periods, and group dates for analysis.

Q2. What is the difference between DATE() and DATEPARSE()?

Answer: DATE() attempts to convert a recognizable expression into a date. DATEPARSE() uses an explicit date format to interpret a text value and is available only for supported data sources.

Q3. What is the difference between DATEPART() and DATENAME()?

Answer: DATEPART() returns a date component as an integer, whereas DATENAME() returns it as text.

Q4. What is DATEADD() used for?

Answer: DATEADD() adds or subtracts a specified interval, such as days, weeks, months, or years, from a date.

Q5. What does DATEDIFF() do?

Answer: DATEDIFF() calculates the difference between two dates in a selected unit. It counts date-part boundaries rather than always representing exact elapsed duration.

Q6. What is DATETRUNC()?

Answer: DATETRUNC() returns a date truncated to the beginning of a specified period, such as a month, quarter, or year.

Q7. What is the difference between TODAY() and NOW()?

Answer: TODAY() returns the current date, while NOW() returns the current date and time.

Q8. How can you calculate shipping time?

Answer: Use DATEDIFF('day', [Order Date], [Ship Date]) to calculate the number of day boundaries between ordering and shipping.

Q9. How do you group sales by month?

Answer: Use a recognized date field at the month level or create DATETRUNC('month', [Order Date]) and aggregate sales by that field.

Q10. Why can DATEDIFF() return a surprising result?

Answer: It counts boundaries of the chosen date part. For example, dates only a few days apart can have a month difference of 1 if they fall in different calendar months.

Q11. What is a date hierarchy?

Answer: A date hierarchy allows users to navigate from higher-level periods such as year and quarter to lower-level periods such as month and day.

Q12. What is the difference between a discrete and continuous date?

Answer: A discrete date creates separate date categories or headers, while a continuous date creates an axis across a date range.

Q13. How can you identify overdue orders?

Answer: Compare the due date with TODAY() and check that the order is not completed. Handle missing due dates and statuses appropriately.

Q14. How do you convert a date stored as text?

Answer: Use DATE() if Tableau recognizes the format, or DATEPARSE() with the matching format pattern where supported.

Q15. Why is DATETRUNC() useful in time-series analysis?

Answer: It standardizes dates to the start of a period so records can be grouped consistently by month, quarter, or year.


24. Quick Revision Checklist

  • ☐ Understand date and datetime data types.
  • ☐ Convert dates with DATE() and DATEPARSE().
  • ☐ Create dates with MAKEDATE() where supported.
  • ☐ Extract components with YEAR(), MONTH(), DAY(), QUARTER(), and WEEK().
  • ☐ Use DATEPART() for numeric date components.
  • ☐ Use DATENAME() for textual date components.
  • ☐ Add or subtract date intervals with DATEADD().
  • ☐ Calculate date-part differences with DATEDIFF().
  • ☐ Group dates with DATETRUNC().
  • ☐ Use TODAY() and NOW() for current-date or current-time calculations.
  • ☐ Understand date hierarchies and discrete versus continuous dates.
  • ☐ Check week-start settings, NULL values, and time-zone behavior.
  • ☐ Practice building date-based charts and dashboards.

25. Conclusion

Date functions are essential for time-based analysis in Tableau. Functions such as DATE(), DATEPARSE(), YEAR(), MONTH(), DATEPART(), DATENAME(), DATEADD(), DATEDIFF(), and DATETRUNC() help analysts convert dates, extract components, calculate durations, define reporting periods, and identify overdue or upcoming events.

Practice these calculations with order, sales, delivery, and customer datasets. Test results against known dates and use the resulting fields in dashboards to develop practical Tableau skills.

Continue Learning: Explore JustAcademy Tableau Training | Register for a Tableau Course Demo

Official Reference: Tableau Date Functions Documentation

whatsapp